use std::sync::{Arc, Mutex, Condvar};
use std::thread;
use std::time::Duration;

fn mai2() {
    let pair = Arc::new((Mutex::new(false), Condvar::new()));
    let pair_clone = Arc::clone(&pair);
    let handle = thread::spawn(move || {
        let (lock, cvar) = &*pair_clone;
        thread::sleep(Duration::from_secs(10));
        println!("[Worker] 任务完成！");
        let mut completed = lock.lock().unwrap();
        *completed = true;
        cvar.notify_one();
    });
    let (lock, cvar) = &*pair;
    let mut completed = lock.lock().unwrap();
    while !*completed {
        println!("[Main] 等待任务完成...");
        completed = cvar.wait(completed).unwrap();
    }
    println!("[Main] 检测到任务完成，继续执行！");
    handle.join().unwrap();
}